 
// pages/hoteldetail/hoteldetail.js
Page({
  data: {
    aid:"",
    useres: [],
    isShowConfirm: false,
    uid:'',
    phone:'',
    userInfo:[],
    hasUserInfo:''
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("跳转")
    this.data.aid = options.aid;
    console.log(this.data.aid)
    console.log("跳转")
    wx.setNavigationBarTitle({
      title: '授权登录'
    })
  },


  getUserProfile(e) {
    var that = this
    wx.getUserProfile({
      desc: '用于完善会员资料', 
      success: (res) => {
        console.log("授权登陆")
        console.log(res.userInfo)
        wx.setStorage({
          key: "userInfo",
          data: res.userInfo
        })
        console.log("授权登陆")
        that.data.userInfo = res.userInfo
        that.data.hasUserInfo = true
        that.bindGetUserInfo()
      }
    })
  },
  
  bindGetUserInfo: function (e) {
    wx.login({
      success: res => {
        console.log("用户的code:" + res.code);
        var call = require("../../../utils/request.js")
        var url = 'getopenid?js_code=' + res.code;
        call.getData(url, this.getopenid, this.fail)

      }
    })
  },

  wxlogin: function (res) {
    var that = this
    // that.uid = res.data
    this.setData({
      uid: res.data
    })


   var call = require("../../../utils/request.js")

    var url = 'ifmobile?openid=' + wx.getStorageSync("openid");

    var rese = call.getData(url, that.ifmobile, that.fail)
   

  },


  getopenid: function (res) {

    wx.setStorage({
      key: "openid",
      data: res.msg
    })
    console.log(wx.getStorageSync("userInfo"))
    this.isLogin = true
    var call = require("../../../utils/request.js")
    var url = 'wxlogin?avatarUrl=' + wx.getStorageSync("userInfo").avatarUrl + '&city=' + wx.getStorageSync("userInfo").city + '&country=' + wx.getStorageSync("userInfo").country + '&gender=' + wx.getStorageSync("userInfo").gender + '&language=' + wx.getStorageSync("userInfo").language + '&nickName=' + wx.getStorageSync("userInfo").nickName + '&province=' + wx.getStorageSync("userInfo").province + '&openid=' + wx.getStorageSync("openid");
    call.getData(url, this.wxlogin, this.fail)
  },


  ifmobile: function (e) {
  
      console.log("jsw-phone")



     console.log(e.msg)
      //wmc
     if(e.msg == 'success'){
  
        wx.setStorage({
          key: "uid",
          data: this.data.uid
        })

        wx.navigateTo({
          url: '/activity/pages/activity/activity?scene='+this.data.aid,
        })

     }else{
     

      this.setData({
        isShowConfirm: true,
      })

     }

  },

  setValue: function (e) {
  
    this.setData({
      phone: e.detail.value
    })
  },





    update: function (e) {
      console.log(52)
      console.log(this.useres)
      console.log(this.data.uid)

      if(e.msg ='success'){
          //更新成功
        this.setData({
          isShowConfirm: false,
        })


      wx.showToast({
        title: '手机号设置成功!',  //标题
        icon: 'success',  
        duration: 2000
      })

        wx.setStorage({
          key: "uid",
          data: this.data.uid
        })

      wx.switchTab({
        url: '../index/index',
        success: function (e) {
          var page = getCurrentPages().pop();
          if (page == undefined || page == null) return;
          page.onLoad();
        }
      })


      }else{
         //更新失败
         wx.showToast({
          title: '手机号设置失败!',  //标题
          icon: 'none',  
          duration: 2000
        })
  
      }
     
    },



  quxiao: function (e) {
    wx.navigateTo({
      url: '/activity/pages/activity/activity?scene='+this.data.aid,
    })
  },


  cancel: function () {
    console.log(1)
    var that = this
    that.setData({
      isShowConfirm: false,
    })

    wx.switchTab({
      url: '/pages/index/index'
    })
  },



  confirmAcceptance:function(){
    console.log(2)
    var that = this
    if(this.data.phone == ''){
      wx.showToast({  
        title: '请输入手机号',  
      
    icon: 'none',
        duration: 2000  
    })  
      return false
    }      
    var call = require("../../../utils/request.js")
    var url = 'updateuser?uid=' + this.data.uid + '&phone=' + this.data.phone;
    call.getData(url, this.update, this.fail)
    

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})